<?php
session_start();
if (isset($_SESSION['openid']) && isset($_POST['name']) && isset($_POST['phone']) && isset($_POST['dizhi'])){
    include '../c/config.php';
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
    $openid=$_SESSION['openid'];
    $name=addslashes(trim($_POST['name']));
    $phone=addslashes(trim($_POST['phone']));
    $dizhi=addslashes(trim($_POST['dizhi']));
    $yuce=addslashes(trim($_POST['yuce']));
    
 
    $queryJ=$mysqli->query("SELECT id from `uinfo` where openid='".$openid."' limit 0,1 ");
    if($queryJ->num_rows>0){
        $mysqli->query("update `uinfo` set name='".$name."', phone='".$phone."', dizhi='".$dizhi."', yuce='".$yuce."' where openid='".$openid."' ");
    }else{
        $mysqli->query("insert into uinfo(openid,name,phone,dizhi,yuce,createtime) values('".$openid."','".$name."','".$phone."','".$dizhi."','".$yuce."','".date("Y-m-d H:i:s")."') ");
    }
    $mysqli->query("insert into uinfo_log(openid,name,phone,dizhi,yuce,createtime) values('".$openid."','".$name."','".$phone."','".$dizhi."','".$yuce."','".date("Y-m-d H:i:s")."') ");
    
    $mysqli->close();
    echo json_encode(array('s'=>'ok'));
}
